<#assign className = model.className>
<#assign classNameLower = className?uncap_first>
package ${basepackage}.${moduleName}.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import tso.fk.dao.BaseFkDao;
import tso.dao.*;
import tso.lang.BaseException;
import tso.util.ValidateUtil;

import ${basepackage}.${moduleName}.dao.I${className}Dao;
import ${basepackage}.${moduleName}.model.${className};

/**
 * ${model.tableAlias} Dao接口实现类
 * @author codeGener
 * @version 1.0
 * @created ${now?string("yyyy-MM-dd HH:mm")}
 */
@Repository("${moduleName}.${className}Dao")
public class ${model.className}Dao extends BaseFkDao implements I${model.className}Dao {
	
	public ${model.className}Dao()	{
		super.modelClass=${className}.class;
		super.defaultOrder="";//ex: billNo desc
	}
	
	<#if !model.fatherClazz??>
	private String buildQueryString(Map<String,Object>  paramMap){
		StringBuilder hql =  new StringBuilder("select obj from ${className} obj where obj.dataState='1'");
		<#list model.queryCols as prop>
		 <#if (!prop.name?ends_with("remark")) && prop.name != "versionNo" && prop.name != "class">
		 if (paramMap.containsKey("${prop.name}")
					&&!ValidateUtil.isEmpty((String)paramMap.get("${prop.name}"))) {
			hql.append("and obj.${prop.name} =").append("'"+paramMap.get("${prop.name}")+"'");
		 }
		 </#if>
		</#list>
		//order by 
		return hql.toString();
	}
	<#if pageable==true>
	public Page find${className}PageBySearch(Map<String,Object> paramMap,int pageNumber,int pageSize){
		try {
			String hql = buildQueryString(paramMap);
			Page page = this.findPage(hql, pageNumber, pageSize);
			return page;
		}catch (Exception e) {
			throw new BaseException(e, log);
		}
	}
	<#else>
	public List find${className}ListBySearch(Map<String,Object> paramMap){
		try {
			String hql = buildQueryString(paramMap);
			List<${className}> resultList = this.find(hql);
			return resultList;
		}catch (Exception e) {
			throw new BaseException(e, log);
		}
	}
	</#if>
	<#else>
	
	public List<${className}> find${className}s(String ${model.fkProperty.name}){
		try {
			String hql = "from ${className} where  dataState='1' and ${model.fkProperty.name}= ?";
			//hql += " order by XX asc ";
			List<${className}> result =  this.find(hql,${model.fkProperty.name});
			return result==null?new ArrayList<${className}>(0):result;
		}
		catch (Exception e) {
			throw new BaseException(e, log);
		}
	}
	</#if>
}